#![allow(dead_code, mutable_transmutes, non_camel_case_types, non_snake_case, non_upper_case_globals, unused_assignments, unused_mut)]
extern crate libc;
use primary::alloc_testing::*;
use primary::arraylist::*;
use primary::compare_pointer::*;
use primary::compare_string::*;
use primary::compare_int::*;
use primary::hash_pointer::*;
use primary::hash_string::*;
use primary::hash_int::*;
extern "C" {
    fn __assert_fail(
        __assertion: *const libc::c_char,
        __file: *const libc::c_char,
        __line: libc::c_uint,
        __function: *const libc::c_char,
    ) -> !;
                                                    }
#[no_mangle]
pub static mut variable1: libc::c_int = 0;
#[no_mangle]
pub static mut variable2: libc::c_int = 0;
#[no_mangle]
pub static mut variable3: libc::c_int = 0;
#[no_mangle]
pub static mut variable4: libc::c_int = 0;
#[no_mangle]
pub extern "C" fn generate_arraylist() -> *mut ArrayList {
    let mut arraylist: *mut ArrayList = std::ptr::null_mut();
    let mut i: libc::c_int = 0;

    arraylist = arraylist_new(0);
    let arraylist_box = unsafe { Box::from_raw(arraylist) };

    while i < 4 {
        arraylist_append(arraylist, unsafe { &mut variable1 as *mut libc::c_int as ArrayListValue });
        arraylist_append(arraylist, unsafe { &mut variable2 as *mut libc::c_int as ArrayListValue });
        arraylist_append(arraylist, unsafe { &mut variable3 as *mut libc::c_int as ArrayListValue });
        arraylist_append(arraylist, unsafe { &mut variable4 as *mut libc::c_int as ArrayListValue });
        i += 1;
    }

    arraylist = Box::into_raw(arraylist_box);
    arraylist
}
#[no_mangle]
pub extern "C" fn test_arraylist_new_free() {
    let mut arraylist: *mut ArrayList = std::ptr::null_mut();

    arraylist = arraylist_new(0);
    let arraylist_box = unsafe { Box::from_raw(arraylist) };
    assert!(!arraylist.is_null(), "arraylist != NULL");
    arraylist = Box::into_raw(arraylist_box);
    arraylist_free(arraylist);

    arraylist = arraylist_new(10);
    let arraylist_box = unsafe { Box::from_raw(arraylist) };
    assert!(!arraylist.is_null(), "arraylist != NULL");
    arraylist = Box::into_raw(arraylist_box);
    arraylist_free(arraylist);

    arraylist_free(std::ptr::null_mut());
}
#[no_mangle]
pub extern "C" fn test_arraylist_append() {
    let mut arraylist: *mut ArrayList = std::ptr::null_mut();
    let mut i: libc::c_int = 0;

    arraylist = arraylist_new(0);
    let arraylist_box = unsafe { Box::from_raw(arraylist) };

    assert_eq!(arraylist_box.length, 0);
    assert_ne!(arraylist_append(arraylist, unsafe { &mut variable1 as *mut libc::c_int as ArrayListValue }), 0);
    assert_eq!(arraylist_box.length, 1);
    assert_ne!(arraylist_append(arraylist, unsafe { &mut variable2 as *mut libc::c_int as ArrayListValue }), 0);
    assert_eq!(arraylist_box.length, 2);
    assert_ne!(arraylist_append(arraylist, unsafe { &mut variable3 as *mut libc::c_int as ArrayListValue }), 0);
    assert_eq!(arraylist_box.length, 3);
    assert_ne!(arraylist_append(arraylist, unsafe { &mut variable4 as *mut libc::c_int as ArrayListValue }), 0);
    assert_eq!(arraylist_box.length, 4);
    assert_eq!(unsafe { *arraylist_box.data.offset(0) }, unsafe { &mut variable1 as *mut libc::c_int as ArrayListValue });
    assert_eq!(unsafe { *arraylist_box.data.offset(1) }, unsafe { &mut variable2 as *mut libc::c_int as ArrayListValue });
    assert_eq!(unsafe { *arraylist_box.data.offset(2) }, unsafe { &mut variable3 as *mut libc::c_int as ArrayListValue });
    assert_eq!(unsafe { *arraylist_box.data.offset(3) }, unsafe { &mut variable4 as *mut libc::c_int as ArrayListValue });

    i = 0;
    while i < 10000 {
        assert_ne!(arraylist_append(arraylist, std::ptr::null_mut()), 0);
        i += 1;
    }

    arraylist = Box::into_raw(arraylist_box);
    arraylist_free(arraylist);
}
#[no_mangle]
pub extern "C" fn test_arraylist_prepend() {
    let mut arraylist: *mut ArrayList = std::ptr::null_mut();
    let mut i: libc::c_int = 0;

    arraylist = arraylist_new(0);
    let arraylist_box = unsafe { Box::from_raw(arraylist) };
    assert_eq!(arraylist_box.length, 0);
    assert_ne!(
        arraylist_prepend(arraylist, unsafe { &mut variable1 as *mut libc::c_int as ArrayListValue }),
        0
    );
    assert_eq!(arraylist_box.length, 1);
    assert_ne!(
        arraylist_prepend(arraylist, unsafe { &mut variable2 as *mut libc::c_int as ArrayListValue }),
        0
    );
    assert_eq!(arraylist_box.length, 2);
    assert_ne!(
        arraylist_prepend(arraylist, unsafe { &mut variable3 as *mut libc::c_int as ArrayListValue }),
        0
    );
    assert_eq!(arraylist_box.length, 3);
    assert_ne!(
        arraylist_prepend(arraylist, unsafe { &mut variable4 as *mut libc::c_int as ArrayListValue }),
        0
    );
    assert_eq!(arraylist_box.length, 4);
    assert_eq!(
        unsafe { *((*arraylist_box).data).offset(0) },
        unsafe { &mut variable4 as *mut libc::c_int as ArrayListValue }
    );
    assert_eq!(
        unsafe { *((*arraylist_box).data).offset(1) },
        unsafe { &mut variable3 as *mut libc::c_int as ArrayListValue }
    );
    assert_eq!(
        unsafe { *((*arraylist_box).data).offset(2) },
        unsafe { &mut variable2 as *mut libc::c_int as ArrayListValue }
    );
    assert_eq!(
        unsafe { *((*arraylist_box).data).offset(3) },
        unsafe { &mut variable1 as *mut libc::c_int as ArrayListValue }
    );

    i = 0;
    while i < 10000 {
        assert_ne!(
            arraylist_prepend(arraylist, std::ptr::null_mut()),
            0
        );
        i += 1;
    }

    arraylist = Box::into_raw(arraylist_box);
    arraylist_free(arraylist);
}
#[no_mangle]
pub extern "C" fn test_arraylist_insert() {
    let mut arraylist: *mut ArrayList = std::ptr::null_mut();
    let mut i: libc::c_int = 0;

    arraylist = generate_arraylist();
    let arraylist_box = unsafe { Box::from_raw(arraylist) };
    assert_eq!(arraylist_box.length, 16);
    assert_eq!(arraylist_insert(arraylist, 17, unsafe { &mut variable1 as *mut libc::c_int as ArrayListValue }), 0);
    assert_eq!(arraylist_box.length, 16);
    assert_eq!(arraylist_box.length, 16);
    assert_eq!(arraylist_box.length, 16);
    assert_eq!(unsafe { *((*arraylist_box).data).offset(4) }, unsafe { &mut variable1 as *mut libc::c_int as ArrayListValue });
    assert_eq!(unsafe { *((*arraylist_box).data).offset(5) }, unsafe { &mut variable2 as *mut libc::c_int as ArrayListValue });
    assert_eq!(unsafe { *((*arraylist_box).data).offset(6) }, unsafe { &mut variable3 as *mut libc::c_int as ArrayListValue });
    assert_ne!(arraylist_insert(arraylist, 5, unsafe { &mut variable4 as *mut libc::c_int as ArrayListValue }), 0);
    assert_eq!(arraylist_box.length, 17);
    assert_eq!(unsafe { *((*arraylist_box).data).offset(4) }, unsafe { &mut variable1 as *mut libc::c_int as ArrayListValue });
    assert_eq!(unsafe { *((*arraylist_box).data).offset(5) }, unsafe { &mut variable4 as *mut libc::c_int as ArrayListValue });
    assert_eq!(unsafe { *((*arraylist_box).data).offset(6) }, unsafe { &mut variable2 as *mut libc::c_int as ArrayListValue });
    assert_eq!(unsafe { *((*arraylist_box).data).offset(7) }, unsafe { &mut variable3 as *mut libc::c_int as ArrayListValue });
    assert_eq!(unsafe { *((*arraylist_box).data).offset(0) }, unsafe { &mut variable1 as *mut libc::c_int as ArrayListValue });
    assert_eq!(unsafe { *((*arraylist_box).data).offset(1) }, unsafe { &mut variable2 as *mut libc::c_int as ArrayListValue });
    assert_eq!(unsafe { *((*arraylist_box).data).offset(2) }, unsafe { &mut variable3 as *mut libc::c_int as ArrayListValue });
    assert_ne!(arraylist_insert(arraylist, 0, unsafe { &mut variable4 as *mut libc::c_int as ArrayListValue }), 0);
    assert_eq!(arraylist_box.length, 18);
    assert_eq!(unsafe { *((*arraylist_box).data).offset(0) }, unsafe { &mut variable4 as *mut libc::c_int as ArrayListValue });
    assert_eq!(unsafe { *((*arraylist_box).data).offset(1) }, unsafe { &mut variable1 as *mut libc::c_int as ArrayListValue });
    assert_eq!(unsafe { *((*arraylist_box).data).offset(2) }, unsafe { &mut variable2 as *mut libc::c_int as ArrayListValue });
    assert_eq!(unsafe { *((*arraylist_box).data).offset(3) }, unsafe { &mut variable3 as *mut libc::c_int as ArrayListValue });
    assert_eq!(unsafe { *((*arraylist_box).data).offset(15) }, unsafe { &mut variable2 as *mut libc::c_int as ArrayListValue });
    assert_eq!(unsafe { *((*arraylist_box).data).offset(16) }, unsafe { &mut variable3 as *mut libc::c_int as ArrayListValue });
    assert_eq!(unsafe { *((*arraylist_box).data).offset(17) }, unsafe { &mut variable4 as *mut libc::c_int as ArrayListValue });
    assert_ne!(arraylist_insert(arraylist, 18, unsafe { &mut variable1 as *mut libc::c_int as ArrayListValue }), 0);
    assert_eq!(arraylist_box.length, 19);
    assert_eq!(unsafe { *((*arraylist_box).data).offset(15) }, unsafe { &mut variable2 as *mut libc::c_int as ArrayListValue });
    assert_eq!(unsafe { *((*arraylist_box).data).offset(16) }, unsafe { &mut variable3 as *mut libc::c_int as ArrayListValue });
    assert_eq!(unsafe { *((*arraylist_box).data).offset(17) }, unsafe { &mut variable4 as *mut libc::c_int as ArrayListValue });
    assert_eq!(unsafe { *((*arraylist_box).data).offset(18) }, unsafe { &mut variable1 as *mut libc::c_int as ArrayListValue });
    i = 0;
    while i < 10000 {
        arraylist_insert(
            arraylist,
            10,
            unsafe { &mut variable1 as *mut libc::c_int as ArrayListValue },
        );
        i += 1;
    }
    arraylist = Box::into_raw(arraylist_box);
    arraylist_free(arraylist);
}
#[no_mangle]
pub extern "C" fn test_arraylist_remove_range() {
    let mut arraylist: *mut ArrayList = std::ptr::null_mut();
    arraylist = generate_arraylist();

    let arraylist_box = unsafe { Box::from_raw(arraylist) };

    assert_eq!(arraylist_box.length, 16, "arraylist->length == 16");
    assert_eq!(
        unsafe { *((*arraylist_box).data).offset(3) },
        unsafe { &mut variable4 as *mut libc::c_int as ArrayListValue },
        "arraylist->data[3] == &variable4"
    );
    assert_eq!(
        unsafe { *((*arraylist_box).data).offset(4) },
        unsafe { &mut variable1 as *mut libc::c_int as ArrayListValue },
        "arraylist->data[4] == &variable1"
    );
    assert_eq!(
        unsafe { *((*arraylist_box).data).offset(5) },
        unsafe { &mut variable2 as *mut libc::c_int as ArrayListValue },
        "arraylist->data[5] == &variable2"
    );
    assert_eq!(
        unsafe { *((*arraylist_box).data).offset(6) },
        unsafe { &mut variable3 as *mut libc::c_int as ArrayListValue },
        "arraylist->data[6] == &variable3"
    );

    arraylist_remove_range(arraylist, 4, 3);

    assert_eq!(arraylist_box.length, 13, "arraylist->length == 13");
    assert_eq!(
        unsafe { *((*arraylist_box).data).offset(3) },
        unsafe { &mut variable4 as *mut libc::c_int as ArrayListValue },
        "arraylist->data[3] == &variable4"
    );
    assert_eq!(
        unsafe { *((*arraylist_box).data).offset(4) },
        unsafe { &mut variable4 as *mut libc::c_int as ArrayListValue },
        "arraylist->data[4] == &variable4"
    );
    assert_eq!(
        unsafe { *((*arraylist_box).data).offset(5) },
        unsafe { &mut variable1 as *mut libc::c_int as ArrayListValue },
        "arraylist->data[5] == &variable1"
    );
    assert_eq!(
        unsafe { *((*arraylist_box).data).offset(6) },
        unsafe { &mut variable2 as *mut libc::c_int as ArrayListValue },
        "arraylist->data[6] == &variable2"
    );

    arraylist_remove_range(arraylist, 10, 10);
    arraylist_remove_range(arraylist, 0, 16);

    assert_eq!(arraylist_box.length, 13, "arraylist->length == 13");

    arraylist = Box::into_raw(arraylist_box);
    arraylist_free(arraylist);
}
#[no_mangle]
pub extern "C" fn test_arraylist_remove() {
    let mut arraylist: *mut ArrayList = std::ptr::null_mut();
    arraylist = generate_arraylist();

    let arraylist_box = unsafe { Box::from_raw(arraylist) };

    assert_eq!(arraylist_box.length, 16);
    assert_eq!(unsafe { *((*arraylist_box).data).offset(3) }, unsafe { &mut variable4 as *mut libc::c_int as ArrayListValue });
    assert_eq!(unsafe { *((*arraylist_box).data).offset(4) }, unsafe { &mut variable1 as *mut libc::c_int as ArrayListValue });
    assert_eq!(unsafe { *((*arraylist_box).data).offset(5) }, unsafe { &mut variable2 as *mut libc::c_int as ArrayListValue });
    assert_eq!(unsafe { *((*arraylist_box).data).offset(6) }, unsafe { &mut variable3 as *mut libc::c_int as ArrayListValue });

    arraylist_remove(arraylist, 4);

    assert_eq!(arraylist_box.length, 15);
    assert_eq!(unsafe { *((*arraylist_box).data).offset(3) }, unsafe { &mut variable4 as *mut libc::c_int as ArrayListValue });
    assert_eq!(unsafe { *((*arraylist_box).data).offset(4) }, unsafe { &mut variable2 as *mut libc::c_int as ArrayListValue });
    assert_eq!(unsafe { *((*arraylist_box).data).offset(5) }, unsafe { &mut variable3 as *mut libc::c_int as ArrayListValue });
    assert_eq!(unsafe { *((*arraylist_box).data).offset(6) }, unsafe { &mut variable4 as *mut libc::c_int as ArrayListValue });

    arraylist_remove(arraylist, 15);

    assert_eq!(arraylist_box.length, 15);

    arraylist = Box::into_raw(arraylist_box);
    arraylist_free(arraylist);
}
#[no_mangle]
pub extern "C" fn test_arraylist_index_of() {
    let mut entries: [libc::c_int; 10] = [
        89, 4, 23, 42, 16, 15, 8, 99, 50, 30,
    ];
    let mut num_entries: libc::c_int = 0;
    let mut arraylist: *mut ArrayList = std::ptr::null_mut();
    let mut i: libc::c_int = 0;
    let mut index: libc::c_int = 0;
    let mut val: libc::c_int = 0;

    num_entries = (std::mem::size_of::<[libc::c_int; 10]>() as libc::c_ulong)
        .wrapping_div(std::mem::size_of::<libc::c_int>() as libc::c_ulong)
        as libc::c_int;

    arraylist = arraylist_new(0);
    let arraylist_box = unsafe { Box::from_raw(arraylist) };
    i = 0;
    while i < num_entries {
        arraylist_append(
            arraylist,
            unsafe { &mut *entries.as_mut_ptr().offset(i as isize) as *mut libc::c_int as ArrayListValue },
        );
        i += 1;
    }

    i = 0;
    while i < num_entries {
        val = entries[i as usize];
        index = arraylist_index_of(
            arraylist,
            Some(int_equal),
            unsafe { &mut val as *mut libc::c_int as ArrayListValue },
        );
        assert_eq!(index, i, "index == i");
        i += 1;
    }

    val = 0;
    assert!(
        arraylist_index_of(
            arraylist,
            Some(int_equal),
            unsafe { &mut val as *mut libc::c_int as ArrayListValue },
        ) < 0,
        "arraylist_index_of(arraylist, int_equal, &val) < 0"
    );

    val = 57;
    assert!(
        arraylist_index_of(
            arraylist,
            Some(int_equal),
            unsafe { &mut val as *mut libc::c_int as ArrayListValue },
        ) < 0,
        "arraylist_index_of(arraylist, int_equal, &val) < 0"
    );

    arraylist = Box::into_raw(arraylist_box);
    arraylist_free(arraylist);
}
#[no_mangle]
pub extern "C" fn test_arraylist_clear() {
    let mut arraylist: *mut ArrayList = std::ptr::null_mut();

    arraylist = arraylist_new(0);
    let arraylist_box = unsafe { Box::from_raw(arraylist) };
    arraylist_clear(arraylist);
    assert_eq!(arraylist_box.length, 0);
    arraylist_append(arraylist, unsafe { &mut variable1 as *mut libc::c_int as ArrayListValue });
    arraylist_append(arraylist, unsafe { &mut variable2 as *mut libc::c_int as ArrayListValue });
    arraylist_append(arraylist, unsafe { &mut variable3 as *mut libc::c_int as ArrayListValue });
    arraylist_append(arraylist, unsafe { &mut variable4 as *mut libc::c_int as ArrayListValue });
    arraylist_clear(arraylist);
    assert_eq!(arraylist_box.length, 0);
    arraylist = Box::into_raw(arraylist_box);
    arraylist_free(arraylist);
}
#[no_mangle]
pub extern "C" fn test_arraylist_sort() {
    let mut arraylist: *mut ArrayList = std::ptr::null_mut();
    let mut entries: [libc::c_int; 13] = [
        89, 4, 23, 42, 4, 16, 15, 4, 8, 99, 50, 30, 4,
    ];
    let mut sorted: [libc::c_int; 13] = [
        4, 4, 4, 4, 8, 15, 16, 23, 30, 42, 50, 89, 99,
    ];
    let mut num_entries: libc::c_uint = (std::mem::size_of::<[libc::c_int; 13]>() as libc::c_ulong)
        .wrapping_div(std::mem::size_of::<libc::c_int>() as libc::c_ulong)
        as libc::c_uint;
    let mut i: libc::c_uint = 0;

    arraylist = arraylist_new(10);
    let arraylist_box = unsafe { Box::from_raw(arraylist) };

    i = 0;
    while i < num_entries {
        arraylist_prepend(
            arraylist,
            unsafe { &mut *entries.as_mut_ptr().offset(i as isize) as *mut libc::c_int as ArrayListValue },
        );
        i = i.wrapping_add(1);
    }

    arraylist_sort(
        arraylist,
        Some(int_compare),
    );

    assert_eq!(arraylist_box.length, num_entries);

    i = 0;
    while i < num_entries {
        let value = unsafe { *((arraylist_box.data).offset(i as isize)) as *mut libc::c_int };
        assert_eq!(unsafe { *value }, sorted[i as usize]);
        i = i.wrapping_add(1);
    }

    arraylist = Box::into_raw(arraylist_box);
    arraylist_free(arraylist);

    arraylist = arraylist_new(5);
    let arraylist_box = unsafe { Box::from_raw(arraylist) };

    arraylist_sort(
        arraylist,
        Some(int_compare),
    );

    assert_eq!(arraylist_box.length, 0);

    arraylist = Box::into_raw(arraylist_box);
    arraylist_free(arraylist);

    arraylist = arraylist_new(5);
    let arraylist_box = unsafe { Box::from_raw(arraylist) };

    arraylist_prepend(
        arraylist,
        unsafe { &mut *entries.as_mut_ptr().offset(0) as *mut libc::c_int as ArrayListValue },
    );

    arraylist_sort(
        arraylist,
        Some(int_compare),
    );

    assert_eq!(arraylist_box.length, 1);
    assert_eq!(
        unsafe { *((arraylist_box.data).offset(0)) },
        unsafe { &mut *entries.as_mut_ptr().offset(0) as *mut libc::c_int as ArrayListValue }
    );

    arraylist = Box::into_raw(arraylist_box);
    arraylist_free(arraylist);
}
